/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.farmcode.console.ejb.business.custom;

import com.farmcode.base.dao.BaseFilter;
import com.farmcode.base.dao.DAOException;
import com.farmcode.base.manager.FacadeException;
import com.farmcode.console.api.business.BaseMatchManagerBean;
import com.farmcode.console.api.business.custom.ExtMatchManager;
import com.farmcode.console.api.model.Match;
import com.farmcode.console.api.model.Project;
import com.farmcode.console.api.model.Template;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Local;
import javax.ejb.Stateless;

/**
 *
 * @author Oscar Ivan Prado
 */
@Local(ExtMatchManager.class)
@Stateless
public class ExtMatchManagerBean extends BaseMatchManagerBean implements ExtMatchManager {

    @Override
    public List<Match> getMatchByProject(Project project, Template template) throws FacadeException {
        try {
            return matchDAO.find(new MatchFilter(project, template));
        } catch (DAOException ex) {
            throw new FacadeException(ex);
        }
    }

    class MatchFilter extends BaseFilter {

        private Project project;
        private Template template;

        public MatchFilter(Project project, Template template) {
            this.project = project;
            this.template = template;
        }

        @Override
        public void fill() {
            setParameter("project", "match.project = ", project);
            setParameter("template", "match.template = ", template);
        }
    }
}
